package mq

import (
	"time"
	"pd/server/plugin/cache"
)

type MQ interface {
	// 订阅消息
	Subscribe(topic string) error

	// 接收消息
	// 参数：timeout 接收消息超时时间
	// 返回值：
	// ok 是否有收到消息
	// msg 消息指针
	// msgID 消息ID
	Receive(timeout time.Duration) (ok bool, msg *string, msgID *string, err error)

	// 发布消息
	Push(msg *string, delay ...time.Duration) error

	// 删除消息
	Delete(msgID *string) error
}

func NewRedisMQ(topic string) MQ {
	mq := &redisMQ{
		retryTime: 5 * time.Minute,
		topic:     topic,
		redis:     cache.NewRedisClient(),
	}

	return mq
}
